package com.fmdj.bff.driver.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import com.fmdj.bff.driver.controller.form.InsertOrderGpsForm;
import com.fmdj.bff.driver.entity.InsertOrderGpsVo;
import com.fmdj.bff.driver.service.OrderGpsService;
import com.fmdj.common.util.CommonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.ArrayList;

@RestController
@RequestMapping("/order/gps")
@Tag(name = "OrderGpsController", description = "订单GPS服务web接口")
@Slf4j
public class OrderGpsController {

    @Autowired
    private OrderGpsService orderGpsService;

    @PostMapping("/insertOrderGps")
    @Operation(summary = "插入订单Gps记录")
    @SaCheckLogin
    public CommonResult insertOrderGps(@RequestBody @Valid InsertOrderGpsForm form) {
        long driverId = StpUtil.getLoginIdAsLong();
        form.getList().forEach(one->one.setDriverId(driverId));
        int rows = orderGpsService.insertOrderGps(form);
        return CommonResult.ok().put(CommonResult.RETURN_ROW, rows);
    }
}
